﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Toolkit="http://schemas.microsoft.com/wpf/2008/toolkit" 
    xmlns:BusinessComponents="clr-namespace:DotBeer.Business.Components;assembly=DotBeer.Business.Components" 
    xmlns:BusinessEntities="clr-namespace:DotBeer.Business.Entities;assembly=DotBeer.Business.Entities"
    xmlns:Presentation="clr-namespace:DotBeer.UI.WPFClient"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:Behaviors="clr-namespace:DotBeer.UI.WPFClient.Behaviors"
    mc:Ignorable="d"
    x:Class="DotBeer.UI.WPFClient.WindowEdit"
    x:Name="WinEdit"
    Presentation:PositionProperties.SavePositionAndState="True"
    Presentation:InputBindingsProperties.UseInputBindingsProperty="True"
    Title="{Binding WindowTitle}"
    Height="700"
    Width="905"
    Background="{DynamicResource BrushWindowBackground}"
    Icon="/DotBeer.UI.WPFClient;component/Images/icon.ico">
    <Window.Resources>
        <Presentation:DataGridSelectedValueConverter x:Key="dataGridSelectedValueConverter" />
        <ObjectDataProvider x:Key="ItemsListDS" ObjectType="{x:Type BusinessComponents:ItemsList}" d:IsDataSource="True"/>
        <Presentation:ReverseBoolConverter x:Key="reverseBoolConverter"/>
    </Window.Resources>
    <Grid x:Name="LayoutRoot" SnapsToDevicePixels="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.493*"/>
            <ColumnDefinition Width="0.284*"/>
            <ColumnDefinition Width="0.223*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto" MinHeight="255"/>
        </Grid.RowDefinitions>
        <Grid Grid.ColumnSpan="1" Margin="0,0,5,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" MinWidth="69.063"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" MinHeight="64"/>
            </Grid.RowDefinitions>
            <TextBlock HorizontalAlignment="Stretch" x:Name="TextBlockHeroName" FontSize="{DynamicResource FontSizeNormal}" TextWrapping="Wrap" Foreground="#FF000000" Text="{Binding Hero.Name}" VerticalAlignment="Top" Grid.ColumnSpan="1" Margin="5,5,0,0" d:LayoutOverrides="VerticalAlignment" Grid.Column="1"/>
            <Image x:Name="ImageHero" Stretch="Fill" Source="{Binding Hero.ImagePath}" Height="64" Width="64" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,5,0,5" />
            <ComboBox x:Name="ComboBoxAuthor" 
                      Height="{DynamicResource ComboBoxHeight}" 
				      VerticalAlignment="Bottom"
                      Text="dupa nie tekst"
				      Style="{DynamicResource ComboBoxAuthorStyle}" 
                      Width="150" d:LayoutOverrides="Width" 
                      HorizontalAlignment="Left" 
                      Grid.Column="1" 
                      Margin="66,0,0,5"
                      ItemsSource="{Binding Authors, Mode=OneWay}" 
                      SelectedItem="{Binding AuthorName}"
                      Presentation:CommandProperties.Command="{Binding LoadHeroByAuthorNameCommand}"
                      Presentation:ComboBoxProperties.ExecuteCommandAfterDropDownClosed="True"/>
            <TextBlock x:Name="TextBlockAuthorName" 
                       VerticalAlignment="Bottom" 
                       Text="Author" 
                       TextWrapping="Wrap" 
                       FontSize="{DynamicResource FontSizeNormal}" 
                       Foreground="#FF000000" 
                       d:LayoutOverrides="Width" 
                       Grid.Column="1" 
                       HorizontalAlignment="Left" 
                       Margin="5,0,0,5" 
                       FontWeight="Normal" 
                       FontFamily="Arial"/>
        </Grid>
        <Grid Margin="5,0,5,5" Grid.Column="1" Grid.Row="1" Grid.RowSpan="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="105"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="33"/>
                <RowDefinition Height="0.817*"/>
                <RowDefinition Height="60"/>
                <RowDefinition Height="60"/>
            </Grid.RowDefinitions>
            <Toolkit:DataGrid x:Name="DataGridSkills" 
                              IsEnabled="{Binding SelectedValue, Converter={StaticResource dataGridSelectedValueConverter}, ElementName=DataGridSkillBuilds, Mode=OneWay}"
                              AutoGenerateColumns="False" 
                              IsSynchronizedWithCurrentItem="True" 
                              ItemsSource="{Binding Hero.CurrentSkills}" 
                              Grid.Row="1" 
                              Grid.ColumnSpan="1" 
                              Margin="0,0,5,5"
                              Grid.RowSpan="3" 
                              SelectionMode="Single" 
                              ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}" 
                              Style="{DynamicResource DataGridStyle}"
                              Presentation:SelectorProperties.ScrollToFirstItemOnItemsCollectionChanged="True"
                              Presentation:DataGridProperties.MaxRows="25"
                              Presentation:DragDropHelper.IsDragSource="True"
                              Presentation:DragDropHelper.IsDropTarget="True"
                              Presentation:DragDropHelper.DragDropTemplate="{StaticResource SkillDataTemplate}">
                <Toolkit:DataGrid.Columns>
                    <Toolkit:DataGridTextColumn Header="Level" IsReadOnly="True" Binding="{Binding Level}"/>
                    <Toolkit:DataGridTextColumn Header="Name" Binding="{Binding Name}" EditingElementStyle="{StaticResource DataGridColumnEditingStyle}"/>
                </Toolkit:DataGrid.Columns>
            </Toolkit:DataGrid>
            <Button Content="Add new skill build" Command="{Binding AddNewSkillBuildCommand}" x:Name="ButtonAddNewSkillBuild" Style="{DynamicResource ButtonLightStyle}" Width="Auto" Grid.Column="1" Grid.Row="3" Height="50" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Margin="0,0,0,5" d:LayoutOverrides="GridBox"/>
            <Toolkit:DataGrid IsSynchronizedWithCurrentItem="True" 
                              x:Name="DataGridSkillBuilds" 
                              ItemsSource="{Binding Hero.SkillBuilds}" 
                              SelectedValue="{Binding CurrentSkillBuild}" 
                              CanUserAddRows="False" 
                              AutoGenerateColumns="False" 
                              Grid.Row="1" 
                              Grid.Column="1" 
                              SelectionMode="Single" 
                              Grid.RowSpan="1"
                              ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}" 
                              Style="{DynamicResource DataGridStyle}">
                <Toolkit:DataGrid.Columns>
                    <Toolkit:DataGridTextColumn Header="Name" Binding="{Binding Name}" EditingElementStyle="{StaticResource DataGridColumnEditingStyle}"/>
                </Toolkit:DataGrid.Columns>
            </Toolkit:DataGrid>
            <TextBlock HorizontalAlignment="Left" Margin="0,0,0,5" VerticalAlignment="Bottom" FontSize="{DynamicResource FontSizeNormal}" Text="Skill Build" TextWrapping="Wrap" d:LayoutOverrides="HorizontalAlignment"/>
            <Button Content="Clear skill build" Command="{Binding ClearSkillBuildCommand}" x:Name="ButtonClearSkillBuild" Style="{DynamicResource ButtonLightStyle}" Width="Auto" HorizontalAlignment="Stretch" Margin="0,5,0,5" Grid.Column="1" Grid.Row="2" d:LayoutOverrides="GridBox"/>
        </Grid>
        <Presentation:HeroItemsControl x:Name="ItemsControl"
                                   Grid.Column="1" 
                                   Grid.Row="2" 
                                   Grid.ColumnSpan="2" 
                                   Margin="5,0,5,5" 
                                   VerticalAlignment="Stretch"
                                   Presentation:CommandProperties.Command="{Binding AddItemCommand}"/>
        <Grid Grid.Row="1" Grid.RowSpan="2" Margin="0,0,5,5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="105"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="33"/>
                <RowDefinition Height="0.839*"/>
                <RowDefinition Height="61"/>
                <RowDefinition Height="61"/>
            </Grid.RowDefinitions>
            <Toolkit:DataGrid x:Name="DataGridItems" 
                              IsEnabled="{Binding SelectedValue, Converter={StaticResource dataGridSelectedValueConverter}, ElementName=DataGridItemBuilds, Mode=OneWay}"
                              IsSynchronizedWithCurrentItem="True" 
                              ItemsSource="{Binding Hero.CurrentItems}" 
                              AutoGenerateColumns="False" 
                              CanUserAddRows="False" 
                              SelectionMode="Single" 
                              Margin="5,0,5,0" 
                              Grid.Row="1" 
                              Grid.RowSpan="3" 
                              Style="{DynamicResource DataGridStyle}" 
                              ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}"
                              Presentation:SelectorProperties.ScrollToFirstItemOnItemsCollectionChanged="True"
                              Presentation:DragDropHelper.IsDragSource="True"
                              Presentation:DragDropHelper.IsDropTarget="True"
                              Presentation:DragDropHelper.DragDropTemplate="{StaticResource ItemDataTemplate}">
                <Toolkit:DataGrid.Columns>
                    <Toolkit:DataGridTemplateColumn Header="Image">
                        <Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Image Source="{Binding ImagePath}" Width="30" Height="30"/>
                            </DataTemplate>
                        </Toolkit:DataGridTemplateColumn.CellTemplate>
                    </Toolkit:DataGridTemplateColumn>
                    <Toolkit:DataGridTemplateColumn Header="Name">
                        <Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Name}" VerticalAlignment="Center"/>
                            </DataTemplate>
                        </Toolkit:DataGridTemplateColumn.CellTemplate>
                        <Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <ComboBox ItemsSource="{Binding Source={StaticResource ItemsListDS}}" 
                                          SelectedValue="{Binding Name}"
                                          Style="{StaticResource ComboBoxStyle}"/>
                            </DataTemplate>
                        </Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                    </Toolkit:DataGridTemplateColumn>
                    <Toolkit:DataGridTemplateColumn Header="Cost">
                        <Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding TotalCost}" VerticalAlignment="Center"/>
                            </DataTemplate>
                        </Toolkit:DataGridTemplateColumn.CellTemplate>
                    </Toolkit:DataGridTemplateColumn>
                    <Toolkit:DataGridTextColumn Header="Type" Binding="{Binding Type}" EditingElementStyle="{StaticResource DataGridColumnEditingStyle}"/>
                    <Toolkit:DataGridTextColumn Header="Comment" Binding="{Binding Comment}" EditingElementStyle="{StaticResource DataGridColumnEditingStyle}"/>
                </Toolkit:DataGrid.Columns>
            </Toolkit:DataGrid>
            <Button Content="Add new item build" x:Name="ButtonAddNewItemBuild" Command="{Binding AddNewItemBuildCommand}" Style="{DynamicResource ButtonLightStyle}" Grid.Column="1" Grid.Row="3" Margin="0,5,0,0" VerticalAlignment="Top" Height="55"/>
            <Toolkit:DataGrid x:Name="DataGridItemBuilds" 
                             IsSynchronizedWithCurrentItem="True" 
                             AutoGenerateColumns="False" 
                             ItemsSource="{Binding Hero.ItemBuilds}" 
                             SelectedValue="{Binding CurrentItemBuild}" 
                             CanUserAddRows="False" 
                             Grid.Column="1" 
                             Grid.Row="1" 
                             Grid.RowSpan="1" 
                             Margin="0,0,0,5" 
                             Style="{DynamicResource DataGridStyle}" 
                             ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}">
                <Toolkit:DataGrid.Columns>
                    <Toolkit:DataGridTextColumn Header="Name" Binding="{Binding Name}" EditingElementStyle="{StaticResource DataGridColumnEditingStyle}"/>
                </Toolkit:DataGrid.Columns>
            </Toolkit:DataGrid>
            <TextBlock VerticalAlignment="Center" Text="Item Build" TextWrapping="Wrap" FontSize="{DynamicResource FontSizeNormal}" d:LayoutOverrides="HorizontalAlignment, Width" HorizontalAlignment="Left" Margin="5,0,0,0" FontFamily="Arial" FontStyle="Normal"/>
            <Button Content="Clear item build" x:Name="ButtonClearCurrentItemBuild" Command="{Binding ClearItemBuildCommand}" Style="{DynamicResource ButtonLightStyle}" Margin="0,5,0,1" Grid.Column="1" Grid.Row="2"/>
        </Grid>
        <Grid HorizontalAlignment="Stretch" Width="Auto" Grid.RowSpan="1" Grid.Column="2" Margin="0,0,5,5" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="33"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Text="Comments" TextWrapping="Wrap" FontSize="{DynamicResource FontSizeNormal}" Margin="5,0,0,0"/>
            <TextBox HorizontalAlignment="Stretch" 
                     VerticalAlignment="Stretch" 
                     Text="{Binding Hero.Comments}" 
                     TextWrapping="Wrap" 
                     Style="{DynamicResource TextBoxStyle}" 
                     Grid.Row="1" 
                     Margin="5,0,0,5" 
                     AcceptsReturn="True" 
                     VerticalScrollBarVisibility="Auto"/>
        </Grid>
        <Grid Width="Auto" Height="Auto" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,-5,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="99"/>
            </Grid.ColumnDefinitions>
            <Border HorizontalAlignment="Stretch" Grid.ColumnSpan="2" Background="{DynamicResource BrushControlBackgroundLight}" BorderBrush="{DynamicResource ImpassiveColor4}" BorderThickness="{DynamicResource ThicknessSize_1}" CornerRadius="{DynamicResource CornerRadiusSmall}"/>
            <Grid>
                <Button x:Name="ButtonCancel" Style="{DynamicResource ButtonLightStyle}" Content="Cancel" Width="80" HorizontalAlignment="Right" Margin="0,8" Height="25" VerticalAlignment="Bottom">
                	<i:Interaction.Triggers>
                		<i:EventTrigger EventName="Click">
                			<Behaviors:CloseWindowAction TargetName="WinEdit"/>
                		</i:EventTrigger>
                	</i:Interaction.Triggers>
                </Button>
                <Button x:Name="ButtonSave"
                        Command="{Binding SaveBuildCommand}" 
                        Style="{DynamicResource ButtonLightStyle}" 
                        Content="Save" 
                        Height="25" 
                        VerticalAlignment="Top" 
                        Margin="0,8,0,0" 
                        IsEnabled="{Binding (Validation.HasError), Converter={StaticResource reverseBoolConverter}, ElementName=TextBoxAuthorName, Mode=OneWay}" Width="80" HorizontalAlignment="Right"/>
                <TextBox x:Name="TextBoxAuthorName" 
                         Style="{DynamicResource TextBoxStyle}" 
                         VerticalAlignment="Top" 
                         TextWrapping="Wrap" Margin="74,10,100,0">
                    <Binding Path="AuthorName" 
                             Mode="TwoWay"
                             UpdateSourceTrigger="PropertyChanged" 
                             NotifyOnValidationError="True">
                        <Binding.ValidationRules>
                            <Presentation:AuthorNameValidation/>
                        </Binding.ValidationRules>
                    </Binding>
                </TextBox>
                <TextBlock x:Name="TextBlockAuthor" HorizontalAlignment="Left" Margin="8,8,0,0" VerticalAlignment="Top" FontSize="{DynamicResource FontSizeNormal}" Text="Author:" TextWrapping="Wrap"/>
                <TextBlock x:Name="TextBlockDotaVersion" HorizontalAlignment="Left" VerticalAlignment="Bottom" FontSize="{DynamicResource FontSizeNormal}" Text="DotA version:" TextWrapping="Wrap" Margin="8,0,0,8"/>
                <TextBox x:Name="TextBoxDotaVersion" 
                	Style="{DynamicResource TextBoxStyle}" 
                	VerticalAlignment="Bottom" 
                	TextWrapping="Wrap" Text="{Binding Hero.DotaVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="119,0,100,8"/>
            </Grid>
            <Grid Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="0.5*"/>
                    <RowDefinition Height="0.5*"/>
                </Grid.RowDefinitions>
                <Button Command="{Binding DeleteBuildCommand}" Style="{DynamicResource ButtonLightStyle}" Content="Delete build" x:Name="ButtonDeleteBuild" VerticalAlignment="Top" Height="25" HorizontalAlignment="Right" Width="80" Margin="0,8,13,0"/>
                <Button Command="{Binding AddNewBuildCommand}" Style="{DynamicResource ButtonLightStyle}" Content="Add build" x:Name="ButtonAddNewBuild" VerticalAlignment="Bottom" Height="25" HorizontalAlignment="Right" Width="80" Grid.Row="2" Margin="0,0,13,8" />
            </Grid>
        </Grid>
    </Grid>
</Window>